<!DOCTYPE html>
<html lang='en'>

<head>
    <meta charset='UTF-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>Document</title>
    <script src='./vue.global.js'></script>
</head>

<body>
    <div id='app'>
        <!-- 将插槽暴露出来的数据原地解构 -->
        <!-- <todo-list v-slot:default="slotProps"> -->
        <todo-list v-slot:default="{item,index}">
            <!-- 明确声明 item不是父组件的item 而是【插槽接收的props】下的item -->
            <span class="green">{{ index }}:{{ item }}</span>
        </todo-list>
        <hr>

        <!-- 将插槽暴露出来的数据原地解构 并给item起一个别名 -->
        <todo-list v-slot:default="{item:todo,index}">
            <!-- 明确声明 item不是父组件的item 而是【插槽接收的props】下的item -->
            <span class="green">{{ index }}:{{ todo }}</span>
        </todo-list>
        <hr>

        <!-- 如果插槽没有暴露出item则使用默认值 -->
        <todo-list v-slot:default="{item,index,author='思密达'}">
            <i class="fas fa-check"></i>
            <!-- 明确声明 item不是父组件的item 而是【插槽接收的props】下的item -->
            <span class="green">{{ index }}:{{ item }} from {{author}}</span>
        </todo-list>
        <hr>

    </div>

    <script>
        const app = Vue.createApp({
            data() {
                return {
                    count: 0,
                    item: "多拉克"
                }
            }
        })

        app.component(
            "todo-list",
            {
                template: `
                <ul>
                    <li v-for="( item, index ) in items">
                        <!--{item,index} slotProps -->
                        <slot :author="author" :item="item" :index="index"></slot>
                    </li>
                </ul>
                `,
                data() {
                    return {
                        items: ['Feed a cat', 'Buy milk'],
                        author:"宇宙元首金正恩思密达"
                    }
                },
            }
        )
        const vm = app.mount('#app')
    </script>
</body>

</html>